package com.tbit.uqbike.service.business.impl;

import com.tbit.uqbike.enums.SystemCodeEnum;
import com.tbit.uqbike.manager.exception.BaseException;
import com.tbit.uqbike.object.pojo.WorkOrderConfig;
import com.tbit.uqbike.object.value.LoginInfo;
import com.tbit.uqbike.service.business.WorkOrderConfigService;
import com.tbit.uqbike.service.rpcservice.PurviewService;
import com.tbit.uqbike.webmanager.dao.core.WorkOrderConfigDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author ：hzw
 * @date ：Created in 2021/8/23 15:21
 * @description：工单设置业务层
 * @modified By：
 * @version: $
 */
@Service(value = "workOrderConfigService")
public class WorkOrderConfigServiceImpl implements WorkOrderConfigService {
    @Autowired
    private PurviewService purviewService;
    @Autowired
    private WorkOrderConfigDao workOrderConfigDao;

    @Override
    public void edit(LoginInfo loginInfo, WorkOrderConfig workOrderConfig) {
        //权限判断
        if (!purviewService.purviewCheck(loginInfo.id, workOrderConfig.getAccountId())) {
            throw new BaseException(SystemCodeEnum.NO_PRIVILEGE);
        }
        if (workOrderConfigDao.getConfig(workOrderConfig.getAccountId()) != null) {
            workOrderConfigDao.update(workOrderConfig);
        } else {
            workOrderConfig.setRedeploySwitch(1);
            workOrderConfig.setRemark(null);
            workOrderConfigDao.insert(workOrderConfig);
        }
    }

    @Override
    public WorkOrderConfig getConfig(Integer accountId, LoginInfo loginInfo) {
        if (!purviewService.purviewCheck(loginInfo.id, accountId)) {
            throw new BaseException(SystemCodeEnum.NO_PRIVILEGE);
        }
        return workOrderConfigDao.getConfig(accountId);
    }


}
